// import { useRouter } from "vue-router";
// let router = useRouter()
import router from "../router/index.js"
const Modules = import.meta.glob("@/views/**/*.vue");
export const generatorRoutes = (routesData) => {
    // 循环遍历
    routesData?.forEach((bigItem) => {
        let { children, component, icon, name, path, menuName } = bigItem;
        // if (children == null) {

        // } else {

        // }
        // // 一级路由
        // router.addRoute({
        //     name:path.substring(1),
        //     path,
        //     component: Modules[`/src/views${component}`],
        //     meta: {
        //         title:menuName,
        //         icon,
        //     },
        //     redirect: children?.length ? `${path}/${children[0].path}` : undefined,
        // })

        // // 二级路由
        // children.forEach(item => {
        //     console.log(item,"children");   
        //     let { path, component, menuName, icon } = item;
        //     router.addRoute(bigItem.path.substring(1), {
        //         path:path,
        //         component: Modules[`/src/views${component}`],
        //         meta: {
        //             title:menuName,
        //             icon
        //         }
        //     })
        // })
        const parentName = path.substring(1);
        if (path.charAt(0) === "/") {
            path = path
        } else {
           path = "/" + path
        }
        router.addRoute({
            name: parentName,
            path,
            component: Modules[`/src/views${component}.vue`],
            meta: {
                title: menuName,
                icon
            },
            redirect: children?.length ? `${path}/${children[0].path}` : undefined,
            children:
                children?.map(child => ({
                    path: child.path,
                    component: Modules[`/src/views${child.component}.vue`],
                    meta: { title: child.menuName, icon: child.icon },
                })),
        });
    })
}
